package cn.lngaosu.lwyd.module.integration.controller.admin.weibostatusesusertimeline;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.lngaosu.lwyd.framework.common.pojo.PageParam;
import cn.lngaosu.lwyd.framework.common.pojo.PageResult;
import cn.lngaosu.lwyd.framework.common.pojo.CommonResult;
import cn.lngaosu.lwyd.framework.common.util.object.BeanUtils;
import static cn.lngaosu.lwyd.framework.common.pojo.CommonResult.success;

import cn.lngaosu.lwyd.framework.excel.core.util.ExcelUtils;

import cn.lngaosu.lwyd.framework.apilog.core.annotation.ApiAccessLog;
import static cn.lngaosu.lwyd.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.lngaosu.lwyd.module.integration.controller.admin.weibostatusesusertimeline.vo.*;
import cn.lngaosu.lwyd.module.integration.dal.dataobject.weibostatusesusertimeline.WeiboStatusesUsertimelineDO;
import cn.lngaosu.lwyd.module.integration.service.weibostatusesusertimeline.WeiboStatusesUsertimelineService;

@Tag(name = "管理后台 - 最新发表的微博列表")
@RestController
@RequestMapping("/integration/weibo-statuses-usertimeline")
@Validated
public class WeiboStatusesUsertimelineController {

    @Resource
    private WeiboStatusesUsertimelineService weiboStatusesUsertimelineService;

    @PostMapping("/create")
    @Operation(summary = "创建最新发表的微博列表")
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:create')")
    public CommonResult<Long> createWeiboStatusesUsertimeline(@Valid @RequestBody WeiboStatusesUsertimelineSaveReqVO createReqVO) {
        return success(weiboStatusesUsertimelineService.createWeiboStatusesUsertimeline(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新最新发表的微博列表")
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:update')")
    public CommonResult<Boolean> updateWeiboStatusesUsertimeline(@Valid @RequestBody WeiboStatusesUsertimelineSaveReqVO updateReqVO) {
        weiboStatusesUsertimelineService.updateWeiboStatusesUsertimeline(updateReqVO);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除最新发表的微博列表")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:delete')")
    public CommonResult<Boolean> deleteWeiboStatusesUsertimeline(@RequestParam("id") Long id) {
        weiboStatusesUsertimelineService.deleteWeiboStatusesUsertimeline(id);
        return success(true);
    }

    @GetMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除最新发表的微博列表")
                @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:delete')")
    public CommonResult<Boolean> deleteWeiboStatusesUsertimelineList(@RequestParam("ids") List<Long> ids) {
        weiboStatusesUsertimelineService.deleteWeiboStatusesUsertimelineListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得最新发表的微博列表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:query')")
    public CommonResult<WeiboStatusesUsertimelineRespVO> getWeiboStatusesUsertimeline(@RequestParam("id") Long id) {
        WeiboStatusesUsertimelineDO weiboStatusesUsertimeline = weiboStatusesUsertimelineService.getWeiboStatusesUsertimeline(id);
        return success(BeanUtils.toBean(weiboStatusesUsertimeline, WeiboStatusesUsertimelineRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得最新发表的微博列表分页")
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:query')")
    public CommonResult<PageResult<WeiboStatusesUsertimelineRespVO>> getWeiboStatusesUsertimelinePage(@Valid WeiboStatusesUsertimelinePageReqVO pageReqVO) {
        PageResult<WeiboStatusesUsertimelineDO> pageResult = weiboStatusesUsertimelineService.getWeiboStatusesUsertimelinePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WeiboStatusesUsertimelineRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出最新发表的微博列表 Excel")
    @PreAuthorize("@ss.hasPermission('integration:weibo-statuses-usertimeline:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWeiboStatusesUsertimelineExcel(@Valid WeiboStatusesUsertimelinePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WeiboStatusesUsertimelineDO> list = weiboStatusesUsertimelineService.getWeiboStatusesUsertimelinePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "最新发表的微博列表.xls", "数据", WeiboStatusesUsertimelineRespVO.class,
                        BeanUtils.toBean(list, WeiboStatusesUsertimelineRespVO.class));
    }

}